package data;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author David Csejtei, CodeGuide Team, http://codeguide.hu
 */
public class Takers extends Thread {
    
    private int startMoney;
    private static final String host = "localhost";
    
    public Takers(final String name) {
        setName(name);
    }
    
    public void createClientSocket() {
        try {
            //
            Socket socket = new Socket(host,5001);

            //Scanner socketConsole = new Scanner(System.in);
            Scanner socketSocket = new Scanner(socket.getInputStream());

            PrintWriter pw = new PrintWriter(socket.getOutputStream());

            ArrayList<String> command = new ArrayList<String>();
            command.add("hello");
            command.add("bello");
            command.add("ize");
            command.add("exit");

            System.out.println("Command number: "+command.size());

            while(!command.isEmpty()) {
                    //String input = socketConsole.nextLine();
                    String input = command.get(0);

                    pw.println(input);
                    pw.flush();

                    if(input.equals("exit")) {
                            System.out.println("Exit...");
                    }

                    if(socketSocket.hasNext()) {
                            String response = socketSocket.nextLine();
                            System.out.println("Response message: "+response);
                    }

                    command.remove(0);
            }

            pw.close();
            socket.close();
            //
        } catch (UnknownHostException ex) {
                System.out.println(ex.getMessage());
        } catch(IOException ie) {
                System.out.println(ie.getMessage());
        }
    }
    
    @Override
    public void run() {
        System.out.println("#"+getName()+"# | "+Math.round(System.currentTimeMillis()*0.001));
    }
    
}
